<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">

<?php
	require("php/akses.php");
	require("php/render.php");
	require("php/Profile.php");
	require("php/validation.php");
	$errors = array("","","","","","","","");
	if (!isset($_SESSION)) {
		session_start();
		// if(!isset($_SESSION["userid"])) {
			// // jgn lupa di redirect ke mana
		// }
	}
	if ((isset($_GET['id']) && isLogin() && $_GET['id']==getLoginUserid()) || (!(isset($_GET['id'])) && isLogin())) {
			loadLoginUser($userinfo);
		} else {
			if (isset($_GET['id'])) {
				$userinfo=loadUser($_GET['id']);
				//kalo mau redirect di uncomment jgn lupa
				if (!$userinfo) {
					header('Location: index.php');
				}
			} else {
				header('Location: index.php');
			}
		}
		
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<link rel="stylesheet" type="text/css" href="css/style.css" />
	<script type="text/javascript" src="javascript/foodholic.js"></script>
	<script type="text/javascript" src="javascript/Profile.js"></script>
	<script type="text/javascript" src="upload_img.js"></script>
	<link rel="stylesheet" type="text/css" href="css/htmlDatePicker.css" />
	<script type="text/javascript" src="javascript/htmlDatePicker.js"></script>
	<title>Profile</title>
</head>

<body>
	<?php require "header.php"; ?>
	

			<div id="content">
			<div id="lblsignup">
				PROFILE<br /><br />
					<?php 
					if ($userinfo['avatar_path']!="unregistered") {
						 $rezultat='<img src="'.$userinfo['avatar_path'].'" />';
						 $rezultat = urlencode($rezultat);
						echo '<body onload="parent.doneloading(\''.$rezultat.'\')"></body>';
					} else {
						echo 'unregistered';
					}
					?>
			</div>
			
			<div id="showimg"> </div>
			<div id="theformm"> 
				<?php
				if ((isset($_GET['id']) && isLogin() && $_GET['id']==getLoginUserid()) || (!(isset($_GET['id'])) && isLogin())) {
				?>
					<form id="uploadform" action="upload_img.php" method="post" enctype="multipart/form-data" target="uploadframe" onsubmit="uploadimg(this); return false">
				  <input type="file" id="myfile" name="myfile" onChange="AvatarChange();"/>
				  <input type="submit" id="saveavatar_button" value="Save Avatar" disabled="true" />
				  <iframe id="uploadframe" name="uploadframe" src="upload_img.php" width="8" height="8" scrolling="no" frameborder="0"></iframe>
				</form>
				<?php 
				} else {
				?>
					<br/>
				<?php
				}
				?>
				
				
			</div>
			<div id="formreg">
				<div id="blank">
				</div>
				<div id="fields">
					<div class="input_label" id="labelavatar"><br /><br /></div>
					<div class="input_label"><br /></div>
					<div class="input_label">Username :&nbsp </div>
					<div class="input_label">Email :&nbsp </div>
					<div class="input_label"><br /></div>
					<div class="input_label">Gender :&nbsp </div>
					<div id="input_label_about">About Me :&nbsp </div>
				</div>
				
				<div id="validations">
					<div class="validation" >
						
					</div>
					<div class="validation" id="validavatar">
						
					</div>
					<div class="validation" id="validusername">
						
					</div>
					<div class="validation" id="validemail">
						
					</div>
					<div class="validation" >
						
					</div>
					<div class="validation" id="validgender">
						
					</div>
				</div>
				
				<!-- <form name="registration" action="" onsubmit="allValidation()"> -->
				<form name="registration" action="" >
					<div id="inputs">
						<div class="input_box" id="input_avatar" >
							
						</div>
						
							<div class="input_box" id="edit_avatar_button" >
								
							</div>
							
						<div class="input_box">
							<?php echo $userinfo['username']; ?>
						</div>
						<div class="input_box" id="input_email">
							<input type="text" name="text_email" id="text_email"  size="51" value="<?php echo $userinfo['email']; ?>" disabled="true" onChange="EmailChange();" onKeyUp="EmailChange();" />
						</div>
						
							<div class="input_box" id="edit_email_button" >
							<?php
							if ((isset($_GET['id']) && isLogin() && $_GET['id']==getLoginUserid()) || (!(isset($_GET['id'])) && isLogin())) {
							?>
								<input type="button" value="Edit Email" onClick="EditProfileEmail();"/>
							<?php 
							} else {
							?>
								<br/>
							<?php
							}
							?>
							</div>
						<div class="input_box">
							<?php
								if ($userinfo['gender']=='P')
									echo "Female"; 
								else 
									if ($userinfo['gender']=='L')
										echo "Male"; 
									else 
										echo "unregistered"; 
							?>
						</div>
						<div id="input_about">
							<textarea name="text_aboutme" id="text_aboutme" cols="40" rows="10" disabled="true"><?php echo $userinfo['about']; ?></textarea>	
						</div>
						
							<div class="input_box" id="edit_about_button" >
							<?php
							if ((isset($_GET['id']) &&  isLogin() && $_GET['id']==getLoginUserid()) || (!(isset($_GET['id'])) && isLogin())) {
							?>
								<input type="button" value="Edit About" onClick="EditProfileAbout();"/>
								<?php 
							} else {
							?>
								<br/>
							<?php
							}
							?>
							</div>
							<input type="hidden" id="hiddenemail" value="<?php echo $userinfo['email']; ?>" />
							<input type="hidden" id="hiddenaboutme" value="<?php echo $userinfo['about']; ?>" />
							
					</div>
				</form>
					<br/ >ACHIEVEMENTS<br/ >
					<?php
						$i = 0;
						while (isset($userinfo['achievement'][$i])) {
							echo ($i+1).". ";
							echo $userinfo['achievement'][$i]['nama_achievement'];
							echo "<br />";
							$i++;	
						}
						if ($i == 0) {
							echo "none";
						}
					?>
					
					<br/ ><br/ >
					<?php
						while (isset($userinfo['achievement'][$i])) {
							echo ($i+1).". ";
							echo $userinfo['achievement'][$i]['nama_achievement'];
							echo "<br />";
							$i++;	
						}
					?>
					
					<?php
					$contents = $userinfo['contents'];
						if (sizeof($contents) == 0) {
				echo "Konten tidak ditemukan";
			} else {
				echo "<div id='left_nav'>";
				$i = 1;
				foreach ($contents as $content) {
					echo "<div class='LikeContent'>
				<a onmouseover='' style='cursor: pointer;' onclick=\"return likeThis('like$i');\" id='staty'>
					<img src='images/like.png' alt='post' name='gambarLike' />
				</a>
				<a onmouseover='' style='cursor: pointer;' onclick=\"return dislikeThis('like$i');\">
					<img src='images/dislike.png' alt='post' />
				</a>
				<div class='likeCount'><a id='like$i'>${content['likes']}</a></div >
				<div><a id='statlike$i'></a></div>
			</div>";
					$i++;
				}
				echo "</div>";
				
				echo "<div id='contents'>";
				foreach ($contents as $content) {
					echo render($content);
				}
				echo "</div>
					<div class='clear'></div>";
			}
					?>
			</div>
		</div>
		
		<?php require "footer.php"; ?>
</body>
</html>